<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>简易计算器案例</title>
    <script src="./lib/vue-2.4.0.js"></script>
</head>

<body>
    <div id="app">
        <input type="text" v-model="n1">

        <select v-model="opt">
            <option value="0">+</option>
            <option value="1">-</option>
            <option value="2">*</option>
            <option value="3">÷</option>
        </select>

        <input type="text" v-model="n2">

        <input type="button" value="=" v-on:click="getResult">

        <input type="text " v-model="result ">


    </div>
</body>

<script>
    var vm = new Vue({
        el: '#app',
        data: {
            n1: 0,
            n2: 0,
            result: 0,
            opt: '0'
        },
        methods: {
            getResult() {
                console.log("************** " + this.opt);
                switch (this.opt) {
                    case '0':
                        this.result = parseInt(this.n1) + parseInt(this.n2);
                        break;

                    case '1':
                        this.result = parseInt(this.n1) - parseInt(this.n2);
                        break;

                    case '2':
                        this.result = parseInt(this.n1) * parseInt(this.n2);
                        break;

                    case '3':
                        this.result = parseInt(this.n1) / parseInt(this.n2);
                        break;
                }
            }
        }
    });
</script>

</html>